﻿$(function() {
    JSUtility.url = "../../Handler/AjaxHandle.ashx";
    JSUtility.param.ClassName = "OA.Bll.Project.ProjectBillPresenter";
    autoResize({ dataGrid: '#Grid', callback: Initlist });
    //alert(IframeHelper.getParentValue('ContractsID'));
    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加项目支出信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 450,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "25%");
            $('#Add').parent().next().css("left", "25%");
            $('#Add').parent().next().css("top", "25%");
            $('#Add').parent().css("top", "25%");
        }
    });
    $('#div_projectPaymentInfo').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '项目付款信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 800,
        height: 600,
        closed: true
    });
    JSUtility.window_edit_form = $("#Add").find("form");
    JSUtility.window_edit_title = "项目支出信息";
    comboboxInitial();
    $('#Add').show();
    $('#div_projectPaymentInfo').show();
});

function comboboxInitial() {
    //$('#CodeName').combobox({ required: true });
    if (!self.parent.projectInfoManager) {
        JSHelper.combotreeProject('ProjectId', "../../Handler/AjaxProjectTreeHandle.ashx?internaltype=1", 205);
    }
}

var billId = "";

function Initlist(size) {
    if (self.parent.projectInfoManager) {
        JSUtility.param.Options["ProjectId"] = self.parent.parent.project_id;
        JSUtility.replenish = function() {
            $("#ProjectId").val(self.parent.parent.project_id);
        };
        $("#ProjectId").attr("readonly", "readonly");
    }
    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '项目支出信息',
        iconCls: 'icon-save',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 80, sortable: true}]],
        columns: [[
                    { title: '项目编号', field: 'ProjectId', width: 80 },
                    { title: '项目名称', field: 'ProjectName', width: 100 },
        //                    { title: '项目名称', field: 'ProjectName', width: 100 },
                    {title: '甲方合同编号', field: 'ContractAId', width: 120 },
                    { title: '甲方合同名称', field: 'ContractName', width: 100 },
                    { title: '甲方合同金额', field: 'ContractAmount', width: 100 },
                    { title: '收票日期', field: 'BillTime', width: 120 },
                    { title: '收票金额', field: 'BillAmount', width: 120 },
                    { title: '出票单位', field: 'BillCompany', width: 120 },
                    { title: '对应集成项目的阶段', field: 'ProjectPhase', width: 120 },
                    { title: '对应比例', field: 'ProjectPrecent', width: 120 },
                    { title: '计算方式说明', field: 'CalMethod', width: 120 },
                    { title: '状态', field: 'State', width: 120 },
                    { title: '收票累计', field: 'AumBillAmount', width: 120 },
                    { title: '付款累计', field: 'AumPayAmount', width: 120 }
                  ]],
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: JSUtility.add
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function() {
                            JSUtility.update();
                            JSHelper.conbotreeUpdateProject("ProjectId");
                        }
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }, '-',
                    {
                        text: '付款信息',
                        iconCls: 'icon-edit',
                        handler: function() {
                            var row = JSHelper.isDatagridSelected($("#Grid"));
                            if (row == null) return;
                            $('#div_projectPaymentInfo').window('open');
                            $("#div_projectPaymentInfo").find("iframe").attr("src", "ProjectPaymentInfo.htm");
                            billId = row.Id;
                        }
                    }
                  ]
    });
}